package com.sky.mapper;


import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 根据用户id和菜品id、套餐id动态查询购物车数据
     * @param shoppingCart
     */
    List<ShoppingCart> queryCartBydishIdOrSetmealId(ShoppingCart shoppingCart);

    /**
     * 根据id修改购物车的数据
     * @param cart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart cart);

    /**
     * 想购物车添加数据
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time)" +
            " VALUES (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime}) ")
    void addToCart(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void cleanCart(Long userId);


    /**
     * 删除购物车中的商品——清除
     * @param shoppingCart
     */
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteShoppingCartItem(ShoppingCart shoppingCart);

    /**
     * 再来一单，通过订单详情数据批量向购物车插入数据
     * @param shoppingCartList
     */
    void insertOrderDetail(List<ShoppingCart> shoppingCartList);
}
